package com.note.feng.leetcode.algorithms.easy;

public class TwoHundredSeventyEight {

    public int firstBadVersion(int n) {
        int left = 1;
        int right = n;
        while (left < right){
            int mid = (right - left) / 2 + left;
            if(isBadVersion(mid)){
                right = mid;
            }else{
                left = mid + 1;
            }
        }
        return right;
    }

    /* The isBadVersion API is defined in the parent class VersionControl.
      boolean isBadVersion(int version); */
    boolean isBadVersion(int version){
        return version >= 1;
    }

    public static void main(String[] args) {
        TwoHundredSeventyEight t = new TwoHundredSeventyEight();
        t.firstBadVersion(1);

    }

}
